﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Text;
using DapperExtensions.Mapper;
using DapperExtensions.Sql;

namespace DapperExtensions
{
    /// <summary>
    /// 查询条件的数据
    /// </summary>
    public class PredicateData
    {
        /// <summary>
        /// 列名
        /// </summary>
        public string ColumnItem { get; set; }

        private string _openratorItem;
        /// <summary>
        /// 操作符，和Operator的字符值形式对应：比如Eq
        /// </summary>
        public string OperatorItem
        {
            get { return _openratorItem; }
            set
            {
                try
                {
                    var v = (Operator)Enum.Parse(typeof(Operator), value);
                    _openratorItem = value;
                }
                catch (Exception ex)
                {
                    throw new Exception("参数非法，参照Operator枚举字符串传递值", ex);
                }
            }
        }
        /// <summary>
        /// 值
        /// </summary>
        public object Value { get; set; }
        /// <summary>
        /// 是否需要进行非计算，比如!=不等于，可以用 Operatoe.Eq + Not=true 表示
        /// </summary>
        public bool Not { get; set; } = false;

        public Operator GetOperator()
        {
            return (Operator)Enum.Parse(typeof(Operator), OperatorItem);
        }
        public void SetOperator(Operator op)
        {
            _openratorItem = op.ToString();
        }
    }
}